﻿#include "queue.h"

// 初始化头结点
Queue* create_queue() {
	Queue* head = (Queue*)malloc(sizeof(Queue));
	head->next = NULL;
	return head;
}
// 入队
void push(Queue* head, struct exam* data) {
	Queue* p = head;
	while (p->next != NULL) {
		p = p->next;
	}
	Queue* newNode = (Queue*)malloc(sizeof(Queue)); 
	newNode->content = *data;  
	newNode->next = NULL; 
	p->next = newNode; 
}

// 获取队列头的第一个数据
Queue* front(Queue* head) {
	if (head->next == NULL) {
		printf("Queue is empty\n");
		return NULL;
	}
	printf("队列里面第一个数据是：%s\n", head->next->content.data);
	return head->next;
}

// 出队
void pop(Queue* head) {
	if (head->next == NULL) {
		printf("队列是空的!\n");
		return;
	}
	Queue* p = head->next;
	head->next = head->next->next;
	free(p);
}

// 销毁队列
void destroy_queue(Queue* head) {
	Queue* p = head;
	while (p != NULL) {
		Queue* temp = p;
		p = p->next;
		free(temp);
	}
	head = NULL;  // 释放队列后将头指针置为NULL
}

